package com.tencet.service.Impl;

import com.tencet.dao.UserDao;
import com.tencet.dao.impl.UserDaoImpl;
import com.tencet.entity.OpenAccount;
import com.tencet.entity.User;
import com.tencet.service.UserService;
import com.tencet.utils.MD5Utils;

/**
 * @author: aiming    @date: 2022/7/21 10:23
 * @description:
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl();

    @Override
    public boolean check(String phoneNum) {
        //去数据库查询电话号码
        User user = userDao.findByPhoneNum(phoneNum);
        if (user != null){
            return true;
        }
        return false;
    }

    @Override
    public boolean registered(String phoneNum, String password) {
        //将明文密码加密处理
        password = MD5Utils.md5(password);
        int count = userDao.insert(phoneNum,password);
        if (count > 0){
            return true;
        }
        return false;
    }

    @Override
    public User login(String phoneNum, String password) {

        //从页面上传递过来的password是明文
        //需先加密才能和数据库端对应
        password = MD5Utils.md5(password);
        User user = userDao.findByPhoneNumAndPassword(phoneNum,password);

        return user;
    }


    /**
     * @author  Yangjx
     * @param   phoneNum
     * @return  表中受影响行数
     * @date: 2022/7/22 21:09
     */
    @Override
    public int update(String phoneNum) {
        int i = userDao.update(phoneNum);
        return i;
    }

    @Override
    public Integer getAccTypeByPhone(String phoneNum) {
        return userDao.getAccType(phoneNum);
    }

    /**
     * 调用UserDao,根据登录手机号查二类账户号
     * @author Yangjx
     * @param phoneNum 登录手机号
     * @return 账户对象，里面有二类账户号： secondaccountnumber
     */
    @Override
    public OpenAccount getSecondAccountNumberByPhone(String phoneNum) {
        OpenAccount openAccount = userDao.getSecondAccountNumberByPhone(phoneNum);
        return openAccount;
    }
}
